package pacBioSimple;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.ArrayList;
import java.util.List;

import pacBiopackage.GetOpt;

public class PacBioLinkerCheckMainTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		GetOpt go = new GetOpt(args, "o:i:h");
		go.optErr = true;
		int ch = -1;
		
		// process options in command line arguments
		// Set default values
		boolean usagePrint = false;                 
		String filenameInput = "";   
		String filenameOutput="output.txt";
		while ((ch = go.getopt()) != GetOpt.optEOF) 
		{
		    if ((char)ch == 'h') {
		       usagePrint = true;
		   }
		    else if ((char)ch == 'i') {
		    	filenameInput = go.optArgGet();
		    }
		    else if((char)ch =='o')
		    {
		    	filenameOutput = go.optArgGet();
		    }
		    else
		        System.exit(1);                     // undefined option
		}                                           // getopt() returns '?'
		
		if (usagePrint || filenameInput.isEmpty()) {
		    System.out.println("Usage: -i PacBio [ -o outputFile -h]"); //NOI18N
		    System.exit(0);
		}
		
		// @TODO check if files exist
	
		System.out.println("------------------------");
		System.out.println("Command line parameter settings:");
		System.out.println("-i " + filenameInput); //NOI18N
		System.out.println("-o " + filenameOutput); //NOI18N		
		System.out.println("------------------------");
		
		PrintWriter pw=null;
		BufferedReader br = null;
		String header = null;
		try
		{

			Writer fw = new FileWriter(filenameOutput);
			Writer bw = new BufferedWriter(fw);
			pw = new PrintWriter(bw);
			br = new BufferedReader(new FileReader(filenameInput));
			
			//PacBioCorrectionByKmers kmerCorrection = new PacBioCorrectionByKmers(ks,stat,freq_mode,freq_table);
			
			System.out.println("starting correction");
			
			List<String> linkerSeq = new ArrayList<String>();
			
			linkerSeq.add("ATCTCTCTCTTTTCCTCCTCCTCCGTTGTTGTTGTTGAGAGAGAT");
			linkerSeq.add("TCTCTCTCTTTTCCTCCTCCTCCGTTGTTGTTGTTGAGAGAGAT");
			linkerSeq.add("TTAACGGAGGAGGAGGA");
			
			PacBioLinkerCheck linkerCheck = new PacBioLinkerCheck("ATCTCTCTCAACAACAACAACGGAGGAGGAGGAAAAGAGAGAGAT","AACGGAGGAGGAGGA" );
			while(br.ready())
			{
				//test if we are getting a copy of br or if its counting up
				PacBioReadContainer read = new PacBioReadIntoContainer().readIntoContainer(br);
				//System.out.println("read "+ read.getHeader());
				header=read.getHeader();
				linkerCheck.findAndCutLinker(read);
				//System.out.println(read.getOrginalSequence());
				pw.println(read.getHeader());
				pw.println(read.getOrginalSequence());	
				
			}
			pw.flush();
			pw.close();
		}
		catch(Exception e)
		{
			System.out.println("read "+ header);
			e.printStackTrace();
			System.exit(1);
		}

	}

}
